package patrol.mobile.com.mobilepatrol.activity.monitor;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.adapter.BaseViewHolder;
import com.dl7.recycler.listener.OnRecyclerViewItemClickListener;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import okhttp3.Call;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.CommonListActivity;
import patrol.mobile.com.mobilepatrol.api.Urls;
import patrol.mobile.com.mobilepatrol.bean.JiankkElefailrecList;
import patrol.mobile.com.mobilepatrol.bean.JiankkElefailrptList;
import patrol.mobile.com.mobilepatrol.bean.JidianXiufuBean;
import patrol.mobile.com.mobilepatrol.manager.UserManager;
import patrol.mobile.com.mobilepatrol.utils.net.HttpCallBack;
import patrol.mobile.com.mobilepatrol.utils.net.HttpSender;

/**
 * Created by z on 2018/9/19.
 * Des:机电修复
 */

public class JdxgActivity extends CommonListActivity {

    private JiankkElefailrecList jiankkElefailrecList;
    private String name = "";
    private EditText suosouEdit;
    private TextView sousuoText;

    @Override
    protected BaseQuickAdapter initAdapter() {
        return new MyBaseQuickAdapter(this);
    }

    @Override
    protected String initTitleName() {
        return "机电修复";
    }

    @Override
    public void initData() {
        super.initData();
        View itemView = LayoutInflater.from(this).inflate(R.layout.activity_jdxg_top, null);
        suosouEdit = itemView.findViewById(R.id.suosouEdit);
        sousuoText = itemView.findViewById(R.id.sousuoText);
        flContent.addView(itemView);

        mAdapter.setOnItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                startActivity(new Intent(view.getContext(), GuzhangNeiRongActivity.class)
                        .putExtra("id", jiankkElefailrecList.getList().get(position).getId()));
            }
        });
        getHttpData();
        sousuoText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                name = suosouEdit.getText().toString();
                getHttpData();
            }
        });
    }

    private void getHttpData() {
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("orgId", UserManager.getOrgNo());
        hashMap.put("name", name);
        HttpSender sender = new HttpSender(this, baseUrl, Urls.getJiankkElefailrecList);
        sender.requestPost(hashMap, new HttpCallBack(sender) {
            @Override
            public void onError(String code, Call call, Exception e) {

            }

            @Override
            public void onResponse(String code, String response) {
                jiankkElefailrecList = new Gson().fromJson(response, JiankkElefailrecList.class);
                mAdapter.updateItems(jiankkElefailrecList.getList());
            }
        });
    }


    public class MyBaseQuickAdapter extends BaseQuickAdapter<JiankkElefailrecList.ListBean> {

        public MyBaseQuickAdapter(Context context) {
            super(context);
        }

        @Override
        protected int attachLayoutRes() {
            return R.layout.item_jdxf_layout;
        }

        @Override
        protected void convert(BaseViewHolder holder, JiankkElefailrecList.ListBean item) {
            holder.setText(R.id.tv_num, (jiankkElefailrecList.getList().indexOf(item) + 1) + "");
            holder.setText(R.id.itemSfzName, item.getOrg().getOrgName());
            holder.setText(R.id.itemSfzXfType, item.getFailureContent());
            holder.setText(R.id.itemSfzXfJinDu, item.getRepairFlag());
            holder.setText(R.id.itemSfzUserName, "推送人：" + item.getAccount().getName());
            holder.setText(R.id.itemSfzWfTime, item.getDate());
        }
    }
}
